﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;
using System.Collections.Generic;//Please add references
namespace EnterpriseFund.DAL
{
    /// <summary>
    /// 数据访问类:TaxAuditForm
    /// </summary>
    public partial class TaxAuditForm
    {
        public TaxAuditForm()
        { }
        #region  BasicMethod

        public bool ExistsAuditByNsbm(string NSRDZDAH, string beginDate, string endDate)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT count(1) FROM  fund.t_TaxAuditForm  a 
left join (select  FTaxAuditId,COUNT(1) AS counts FROM fund.t_TaxAuditPolicyEval WHERE FIssueID IS NULL GROUP BY FTaxAuditId) AS b
ON a.FTaxAuditId = b.FTaxAuditId 
 WHERE ((DATEDIFF(DAY ,RKRQ_Q,@beginDate)>=0 AND  DATEDIFF(DAY ,@beginDate,RKRQ_Z)>=0 )
 OR(DATEDIFF(DAY ,RKRQ_Q,@endDate)>=0 AND  DATEDIFF(DAY ,@endDate,RKRQ_Z)>=0 )
 OR (DATEDIFF(DAY ,@beginDate,RKRQ_Q)>=0 AND  DATEDIFF(DAY ,RKRQ_Z,@endDate)>=0 )) and NSRDZDAH=@NSRDZDAH and 
 (FAllowanceClassNo<>'Y' or counts>0) ");
            SqlParameter[] parameters = {
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,10),
					new SqlParameter("@beginDate", SqlDbType.DateTime),
					new SqlParameter("@endDate", SqlDbType.DateTime)	};
            parameters[0].Value = NSRDZDAH;
            parameters[1].Value = beginDate;
            parameters[2].Value = endDate;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        public bool ExistsAuditByNsbm2(string NSRDZDAH)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"
SELECT count(*) FROM fund.t_TaxAuditForm b LEFT JOIN fund.t_TaxAuditPolicyEval a ON a.FTaxAuditId = b.FTaxAuditId
LEFT JOIN fund.t_AllowanceIssueEntry c ON a.FIssueID =c.FIssueID AND a.FTaxClassAllowanceNo =c.FTaxClassAllowanceNo AND b.NSRDZDAH = c.NSRDZDAH
LEFT JOIN (SELECT z.FAllowanceFileEntryID,n.FFileNo FROM fund.t_AllowanceFileEntry z LEFT JOIN fund.t_AllowanceFile n ON z.FAllowanceFileID = n.FAllowanceFileID) AS d
ON c.FAllowanceFileEntryID = d.FAllowanceFileEntryID
WHERE (a.FStatus<> '9' AND d.FFileNo IS NULL OR b.FStatus='0' OR b.FStatus ='1' or b.FStatus ='2') AND b.NSRDZDAH=@NSRDZDAH");
            SqlParameter[] parameters = {
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,10)	};
            parameters[0].Value = NSRDZDAH;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        public bool ExistsByYGZ(string NSRDZDAH, string FYear)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT count(1) FROM  fund.t_TaxAuditForm 
 WHERE  NSRDZDAH=@NSRDZDAH and FYear=@FYear and FAllowanceClassNo ='J'");
            SqlParameter[] parameters = {
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,10),
                    new SqlParameter("@FYear", SqlDbType.Decimal,4)	};
            parameters[0].Value = NSRDZDAH;
            parameters[1].Value = FYear;
            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        public void Return(Model.TaxAuditForm tAF)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_TaxAuditForm set ");
            strSql.Append("FStatus=@FStatus,");
            strSql.Append("FIsReturn=@FIsReturn,");
            strSql.Append("FPolicyNote=@FPolicyNote");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId ");
            SqlParameter[] parameters3 = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
                    new SqlParameter("@FIsReturn", SqlDbType.NVarChar,1),
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50),
                    new SqlParameter("@FPolicyNote", SqlDbType.NVarChar,250)
					};
            parameters3[0].Value = tAF.FStatus;
            parameters3[1].Value = tAF.FIsReturn;
            parameters3[2].Value = tAF.FTaxAuditId;
            parameters3[3].Value = tAF.FPolicyNote;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters3;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from fund.t_TaxAuditPolicyEval ");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId");
            SqlParameter[] parameters = {
                    new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,250)
					};
            parameters[0].Value = tAF.FTaxAuditId;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }

        public void UpdateStatus(Model.TaxAuditForm tAF, string status)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_TaxAuditForm set ");
            strSql.Append("FStatus=@FStatus,");
            strSql.Append("FIsReturn=@FIsReturn,");
            strSql.Append("FPolicyNote=@FPolicyNote");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId ");
            SqlParameter[] parameters3 = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
                    new SqlParameter("@FIsReturn", SqlDbType.NVarChar,1),
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50),
                    new SqlParameter("@FPolicyNote", SqlDbType.NVarChar,250)
					};
            parameters3[0].Value = tAF.FStatus;
            parameters3[1].Value = tAF.FIsReturn;
            parameters3[2].Value = tAF.FTaxAuditId;
            parameters3[3].Value = tAF.FPolicyNote;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters3;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_TaxAuditPolicyEval set ");
            strSql.Append("FStatus=@FStatus ");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId  and FAllowanceAmount<>0");
            SqlParameter[] parameters = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
                    new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,250)
					};
            parameters[0].Value = status;
            parameters[1].Value = tAF.FTaxAuditId;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_TaxAuditPolicyEval set ");
            strSql.Append("FStatus=@FStatus ");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId  and FAllowanceAmount = 0");
            SqlParameter[] parameters2 = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
                    new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,250)
					};

            switch (status)
            {
                case "0":
                    parameters2[0].Value = status;
                    break;
                case "2":
                    parameters2[0].Value = 9;
                    break;
            }
            parameters2[1].Value = tAF.FTaxAuditId;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters2;
            cmdList.Add(cmds);

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.TaxAuditForm GetModel(string FTaxAuditId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FIsReturn,FTaxAuditId,FEntityNo,FYear,FAllowanceClassNo,NSRDZDAH,RKRQ_Q,RKRQ_Z,NSRMC,FOldEnterprisePropNo,FOldFinancePropNo,FNewEnterprisePropNo,FNewFinancePropNo,FStatus,FNote,FPolicyNote,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP from fund.t_TaxAuditForm ");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId ");
            SqlParameter[] parameters = {
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50)
		};
            parameters[0].Value = FTaxAuditId;


            EnterpriseFund.Model.TaxAuditForm model = new EnterpriseFund.Model.TaxAuditForm();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获取审核数据
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="strWhere"></param>
        /// <param name="fOrderFiled"></param>
        /// <returns></returns>
        public DataSet GetDataforAuditForSave(string beginDate, string endDate, string Year, string NSRDZDAH)
        {

            SqlParameter[] parameters = {
                    new SqlParameter("@beginDate", SqlDbType.DateTime),
                    new SqlParameter("@endDate", SqlDbType.DateTime),
                    new SqlParameter("@Year", SqlDbType.Decimal,4),
                    new SqlParameter("@NSRBM", SqlDbType.NVarChar,20)
                    };
            parameters[0].Value = beginDate;
            parameters[1].Value = endDate;
            parameters[2].Value = Year;
            parameters[3].Value = NSRDZDAH;

            DataSet ds = DbHelperSQL.RunProcedure("[fund].[sp_GetDataforAuditSave]", parameters, "ds", 60 * 30);

            return ds;
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.TaxAuditForm DataRowToModel(DataRow row)
        {
            EnterpriseFund.Model.TaxAuditForm model = new EnterpriseFund.Model.TaxAuditForm();
            if (row != null)
            {
                if (row["FTaxAuditId"] != null)
                {
                    model.FTaxAuditId = row["FTaxAuditId"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FYear"] != null && row["FYear"].ToString() != "")
                {
                    model.FYear = decimal.Parse(row["FYear"].ToString());
                }
                if (row["FAllowanceClassNo"] != null)
                {
                    model.FAllowanceClassNo = row["FAllowanceClassNo"].ToString();
                }
                if (row["NSRDZDAH"] != null && row["NSRDZDAH"].ToString() != "")
                {
                    model.NSRDZDAH = decimal.Parse(row["NSRDZDAH"].ToString());
                }
                if (row["RKRQ_Q"] != null && row["RKRQ_Q"].ToString() != "")
                {
                    model.RKRQ_Q = DateTime.Parse(row["RKRQ_Q"].ToString());
                }
                if (row["RKRQ_Z"] != null && row["RKRQ_Z"].ToString() != "")
                {
                    model.RKRQ_Z = DateTime.Parse(row["RKRQ_Z"].ToString());
                }
                if (row["FOldEnterprisePropNo"] != null)
                {
                    model.FOldEnterprisePropNo = row["FOldEnterprisePropNo"].ToString();
                }
                if (row["FOldFinancePropNo"] != null)
                {
                    model.FOldFinancePropNo = row["FOldFinancePropNo"].ToString();
                }
                if (row["FNewEnterprisePropNo"] != null)
                {
                    model.FNewEnterprisePropNo = row["FNewEnterprisePropNo"].ToString();
                }
                if (row["FNewFinancePropNo"] != null)
                {
                    model.FNewFinancePropNo = row["FNewFinancePropNo"].ToString();
                }
                if (row["FStatus"] != null)
                {
                    model.FStatus = row["FStatus"].ToString();
                }
                if (row["FNote"] != null)
                {
                    model.FNote = row["FNote"].ToString();
                }
                if (row["FPolicyNote"] != null)
                {
                    model.FPolicyNote = row["FPolicyNote"].ToString();
                }
                if (row["FInsEmpNo"] != null)
                {
                    model.FInsEmpNo = row["FInsEmpNo"].ToString();
                }
                if (row["FInsDeptNo"] != null)
                {
                    model.FInsDeptNo = row["FInsDeptNo"].ToString();
                }
                if (row["FInsDate"] != null && row["FInsDate"].ToString() != "")
                {
                    model.FInsDate = DateTime.Parse(row["FInsDate"].ToString());
                }
                if (row["FIsReturn"] != null && row["FIsReturn"].ToString() != "")
                {
                    model.FIsReturn = row["FIsReturn"].ToString();
                }
                
                if (row["FInsIP"] != null)
                {
                    model.FInsIP = row["FInsIP"].ToString();
                }
                if (row["FUpdEmplNo"] != null)
                {
                    model.FUpdEmplNo = row["FUpdEmplNo"].ToString();
                }
                if (row["FUpdDeptNo"] != null)
                {
                    model.FUpdDeptNo = row["FUpdDeptNo"].ToString();
                }
                if (row["FUpdDate"] != null && row["FUpdDate"].ToString() != "")
                {
                    model.FUpdDate = DateTime.Parse(row["FUpdDate"].ToString());
                }
                if (row["FUpdIP"] != null)
                {
                    model.FUpdIP = row["FUpdIP"].ToString();
                }
                if (row.Table.Columns.Contains("NSRBM"))
                {
                    if (row["NSRBM"] != null)
                    {
                        model.NSRBM = row["NSRBM"].ToString();
                    }
                }

                if (row.Table.Columns.Contains("FNewEnterprisePropName"))
                {
                    if (row["FNewEnterprisePropName"] != null)
                    {
                        model.FNewEnterprisePropName = row["FNewEnterprisePropName"].ToString();
                    }
                }

                if (row.Table.Columns.Contains("FNewFinancePropName"))
                {
                    if (row["FNewFinancePropName"] != null)
                    {
                        model.FNewFinancePropName = row["FNewFinancePropName"].ToString();
                    }
                }

                if (row.Table.Columns.Contains("FEnterprisePropName"))
                {
                    if (row["FEnterprisePropName"] != null)
                    {
                        model.FEnterprisePropName = row["FEnterprisePropName"].ToString();
                    }
                }

                if (row.Table.Columns.Contains("FFinancePropName"))
                {
                    if (row["FFinancePropName"] != null)
                    {
                        model.FFinancePropName = row["FFinancePropName"].ToString();
                    }
                }

                if (row.Table.Columns.Contains("FAllowanceName"))
                {
                    if (row["FAllowanceName"] != null)
                    {
                        model.FAllowanceName = row["FAllowanceName"].ToString();
                    }
                }

                if (row.Table.Columns.Contains("FAdjustAmount"))
                {
                    if (row["FAdjustAmount"] != null && row["FAdjustAmount"].ToString() != "")
                    {
                        model.FAdjustAmount = decimal.Parse(row["FAdjustAmount"].ToString());
                    }
                }

                if (row.Table.Columns.Contains("NSRMC"))
                {
                    if (row["NSRMC"] != null)
                    {
                        model.NSRMC = row["NSRMC"].ToString();
                    }
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FTaxAuditId,FEntityNo,FYear,FAllowanceClassNo,NSRDZDAH,RKRQ_Q,RKRQ_Z,NSRMC,FOldEnterprisePropNo,FOldFinancePropNo,FNewEnterprisePropNo,FNewFinancePropNo,FStatus,FNote,FPolicyNote,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP ");
            strSql.Append(" FROM fund.t_TaxAuditForm ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" FTaxAuditId,FEntityNo,FYear,FAllowanceClassNo,NSRDZDAH,RKRQ_Q,RKRQ_Z,NSRMC,FOldEnterprisePropNo,FOldFinancePropNo,FNewEnterprisePropNo,FNewFinancePropNo,FStatus,FNote,FPolicyNote,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP ");
            strSql.Append(" FROM fund.t_TaxAuditForm ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere,string year)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM fund.[fn_TaxAuditForm](" + year + ") ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        public string Add(Model.TaxAuditForm model, List<Model.TaxAuditAdjust> taxAuditAdjustList, List<Model.TaxAudit_SB_ZSXX> taxAudit_SB_ZSXXList)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            var getBillIdSql = "exec sp_getbillno 'fund.t_TaxAuditForm','FTaxAuditId','','','',@returnBId output ";
            var getBillIdPar = new SqlParameter[]{ 
                new SqlParameter("@returnBId", SqlDbType.VarChar, 50)
            };
            getBillIdPar[0].Direction = ParameterDirection.Output;

            cmds.CommandText = getBillIdSql.ToString();
            cmds.Parameters = getBillIdPar;
            cmdList.Add(cmds);

            cmds = new CommandInfo();

            strSql = new StringBuilder();
            strSql.Append("insert into fund.t_TaxAuditForm(");
            strSql.Append("FTaxAuditId,FEntityNo,FYear,FAllowanceClassNo,NSRDZDAH,RKRQ_Q,RKRQ_Z,NSRMC,FOldEnterprisePropNo,FOldFinancePropNo,FNewEnterprisePropNo,FNewFinancePropNo,FStatus,FNote,FPolicyNote,FInsEmpNo,FInsDeptNo,FInsDate,FInsIP,FUpdEmplNo,FUpdDeptNo,FUpdDate,FUpdIP,FIsReturn)");
            strSql.Append(" values (");
            strSql.Append("@FTaxAuditId,@FEntityNo,@FYear,@FAllowanceClassNo,@NSRDZDAH,@RKRQ_Q,@RKRQ_Z,@NSRMC,@FOldEnterprisePropNo,@FOldFinancePropNo,@FNewEnterprisePropNo,@FNewFinancePropNo,@FStatus,@FNote,@FPolicyNote,@FInsEmpNo,@FInsDeptNo,@FInsDate,@FInsIP,@FUpdEmplNo,@FUpdDeptNo,@FUpdDate,@FUpdIP,@FIsReturn)");
            SqlParameter[] parameters = {
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FAllowanceClassNo", SqlDbType.NVarChar,6),
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
					new SqlParameter("@RKRQ_Q", SqlDbType.DateTime),
					new SqlParameter("@RKRQ_Z", SqlDbType.DateTime),
					new SqlParameter("@NSRMC", SqlDbType.NVarChar,80),
					new SqlParameter("@FOldEnterprisePropNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FOldFinancePropNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FNewEnterprisePropNo", SqlDbType.NVarChar,6),
					new SqlParameter("@FNewFinancePropNo", SqlDbType.NVarChar,6),
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255),
					new SqlParameter("@FPolicyNote", SqlDbType.NVarChar,255),
                    new SqlParameter("@FIsReturn", SqlDbType.NVarChar,1),
					new SqlParameter("@FInsEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FInsDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInsDate", SqlDbType.DateTime),
					new SqlParameter("@FInsIP", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FUpdDate", SqlDbType.DateTime),
					new SqlParameter("@FUpdIP", SqlDbType.VarChar,15)};
            parameters[0].Direction = ParameterDirection.InputOutput;
            parameters[1].Value = model.FEntityNo;
            parameters[2].Value = model.FYear;
            parameters[3].Value = model.FAllowanceClassNo;
            parameters[4].Value = model.NSRDZDAH;
            parameters[5].Value = model.RKRQ_Q;
            parameters[6].Value = model.RKRQ_Z;
            parameters[7].Value = model.NSRMC;
            parameters[8].Value = model.FOldEnterprisePropNo;
            parameters[9].Value = model.FOldFinancePropNo;
            parameters[10].Value = model.FNewEnterprisePropNo;
            parameters[11].Value = model.FNewFinancePropNo;
            parameters[12].Value = model.FStatus;
            parameters[13].Value = model.FNote;
            parameters[14].Value = model.FPolicyNote;
            parameters[15].Value = model.FIsReturn;
            parameters[16].Value = model.FInsEmpNo;
            parameters[17].Value = model.FInsDeptNo;
            parameters[18].Value = model.FInsDate;
            parameters[19].Value = model.FInsIP;
            parameters[20].Value = model.FUpdEmplNo;
            parameters[21].Value = model.FUpdDeptNo;
            parameters[22].Value = model.FUpdDate;
            parameters[23].Value = model.FUpdIP;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            foreach (Model.TaxAuditAdjust modelTA in taxAuditAdjustList)
            {
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("insert into fund.t_TaxAuditAdjust(");
                strSql.Append("FEntityNo,FYear,FTaxClassAllowanceNo,FAdjustAmount,FAdjustDate,RKRQ,FNote,FAdjustDeptNo,FAdjustEmpNo,FAdjustIP,FStatus,FTaxAuditId)");
                strSql.Append(" values (");
                strSql.Append("@FEntityNo,@FYear,@FTaxClassAllowanceNo,@FAdjustAmount,@FAdjustDate,@RKRQ,@FNote,@FAdjustDeptNo,@FAdjustEmpNo,@FAdjustIP,@FStatus,@FTaxAuditId)");
                SqlParameter[] parameters2 = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FAdjustAmount", SqlDbType.Decimal,13),
					new SqlParameter("@FAdjustDate", SqlDbType.DateTime),
					new SqlParameter("@RKRQ", SqlDbType.DateTime),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255),
					new SqlParameter("@FAdjustDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAdjustEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FAdjustIP", SqlDbType.NVarChar,15),
					new SqlParameter("@FStatus", SqlDbType.NVarChar,2),
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50)};
                parameters2[0].Value = modelTA.FEntityNo;
                parameters2[1].Value = modelTA.FYear;
                parameters2[2].Value = modelTA.FTaxClassAllowanceNo;
                parameters2[3].Value = modelTA.FAdjustAmount;
                parameters2[4].Value = modelTA.FAdjustDate;
                parameters2[5].Value = modelTA.RKRQ;
                parameters2[6].Value = modelTA.FNote;
                parameters2[7].Value = modelTA.FAdjustDeptNo;
                parameters2[8].Value = modelTA.FAdjustEmpNo;
                parameters2[9].Value = modelTA.FAdjustIP;
                parameters2[10].Value = modelTA.FStatus;
                parameters2[11].Direction = ParameterDirection.InputOutput;

                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters2;
                cmdList.Add(cmds);
            }

            foreach (Model.TaxAudit_SB_ZSXX modelABZ in taxAudit_SB_ZSXXList)
            {
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("insert into fund.t_TaxAudit_SB_ZSXX(");
                strSql.Append("FTaxAuditId,FDataSource,ZSXH,FYear,FTaxClassAllowanceNo,ZSXM_DM,SE,RKRQ,SSSQ_Q,SSSQ_Z,YSKM_DM,YSFPBL_DM,YSFPBL_ZY,YSFPBL_SS,YSFPBL_DS,YSFPBL_XQ,YSFPBL_XZ,YSFPBL_XC)");
                strSql.Append(" values (");
                strSql.Append("@FTaxAuditId,@FDataSource,@ZSXH,@FYear,@FTaxClassAllowanceNo,@ZSXM_DM,@SE,@RKRQ,@SSSQ_Q,@SSSQ_Z,@YSKM_DM,@YSFPBL_DM,@YSFPBL_ZY,@YSFPBL_SS,@YSFPBL_DS,@YSFPBL_XQ,@YSFPBL_XZ,@YSFPBL_XC)");
                strSql.Append(";select @@IDENTITY");
                SqlParameter[] parameters3 = {
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50),
					new SqlParameter("@FDataSource", SqlDbType.NVarChar,2),
					new SqlParameter("@ZSXH", SqlDbType.Decimal,13),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20),
					new SqlParameter("@ZSXM_DM", SqlDbType.NVarChar,2),
					new SqlParameter("@SE", SqlDbType.Decimal,13),
					new SqlParameter("@RKRQ", SqlDbType.DateTime),
					new SqlParameter("@SSSQ_Q", SqlDbType.DateTime),
					new SqlParameter("@SSSQ_Z", SqlDbType.DateTime),
					new SqlParameter("@YSKM_DM", SqlDbType.NVarChar,15),
					new SqlParameter("@YSFPBL_DM", SqlDbType.NVarChar,10),
					new SqlParameter("@YSFPBL_ZY", SqlDbType.Decimal,5),
					new SqlParameter("@YSFPBL_SS", SqlDbType.Decimal,5),
					new SqlParameter("@YSFPBL_DS", SqlDbType.Decimal,5),
					new SqlParameter("@YSFPBL_XQ", SqlDbType.Decimal,5),
					new SqlParameter("@YSFPBL_XZ", SqlDbType.Decimal,5),
					new SqlParameter("@YSFPBL_XC", SqlDbType.Decimal,5)};
                parameters3[0].Direction = ParameterDirection.InputOutput;
                parameters3[1].Value = modelABZ.FDataSource;
                parameters3[2].Value = modelABZ.ZSXH;
                parameters3[3].Value = modelABZ.FYear;
                parameters3[4].Value = modelABZ.FTaxClassAllowanceNo;
                parameters3[5].Value = modelABZ.ZSXM_DM;
                parameters3[6].Value = modelABZ.SE;
                parameters3[7].Value = modelABZ.RKRQ;
                parameters3[8].Value = modelABZ.SSSQ_Q;
                parameters3[9].Value = modelABZ.SSSQ_Z;
                parameters3[10].Value = modelABZ.YSKM_DM;
                parameters3[11].Value = modelABZ.YSFPBL_DM;
                parameters3[12].Value = modelABZ.YSFPBL_ZY;
                parameters3[13].Value = modelABZ.YSFPBL_SS;
                parameters3[14].Value = modelABZ.YSFPBL_DS;
                parameters3[15].Value = modelABZ.YSFPBL_XQ;
                parameters3[16].Value = modelABZ.YSFPBL_XZ;
                parameters3[17].Value = modelABZ.YSFPBL_XC;

                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters3;
                cmdList.Add(cmds);
            }

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }

            return parameters[0].Value.ToString();
        }

        public void Update(Model.TaxAuditForm model, List<Model.TaxAuditAdjust> taxAuditAdjustList, List<Model.TaxAudit_SB_ZSXX> taxAudit_SB_ZSXXList)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();
            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_TaxAuditForm set ");
            strSql.Append("FStatus=@FStatus,");
            strSql.Append("FNote=@FNote,");
            strSql.Append("FPolicyNote=@FPolicyNote,");
            strSql.Append("FAllowanceClassNo=@FAllowanceClassNo,");
            strSql.Append("FUpdEmplNo=@FUpdEmplNo,");
            strSql.Append("FUpdDeptNo=@FUpdDeptNo,");
            strSql.Append("FUpdDate=@FUpdDate,");
            strSql.Append("FIsReturn=@FIsReturn,");
            strSql.Append("FUpdIP=@FUpdIP");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId ");
            SqlParameter[] parameters = {
                    new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255),
					new SqlParameter("@FPolicyNote", SqlDbType.NVarChar,255),
                    new SqlParameter("@FAllowanceClassNo", SqlDbType.NVarChar,255),
					new SqlParameter("@FUpdEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FUpdDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FUpdDate", SqlDbType.DateTime),
                    new SqlParameter("@FIsReturn", SqlDbType.NVarChar,1),
					new SqlParameter("@FUpdIP", SqlDbType.VarChar,15),
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50)};

            parameters[0].Value = model.FStatus;
            parameters[1].Value = model.FNote;
            parameters[2].Value = model.FPolicyNote;
            parameters[3].Value = model.FAllowanceClassNo;
            parameters[4].Value = model.FUpdEmplNo;
            parameters[5].Value = model.FUpdDeptNo;
            parameters[6].Value = model.FUpdDate;
            parameters[7].Value = model.FIsReturn;
            parameters[8].Value = model.FUpdIP;
            parameters[9].Value = model.FTaxAuditId;
        
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from fund.t_TaxAuditAdjust ");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId ");
            SqlParameter[] parameters4 = {
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50)			};
            parameters4[0].Value = model.FTaxAuditId;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters4;
            cmdList.Add(cmds);

            foreach (Model.TaxAuditAdjust modelTA in taxAuditAdjustList)
            {
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("insert into fund.t_TaxAuditAdjust(");
                strSql.Append("FEntityNo,FYear,FTaxClassAllowanceNo,FAdjustAmount,FAdjustDate,RKRQ,FNote,FAdjustDeptNo,FAdjustEmpNo,FAdjustIP,FStatus,FTaxAuditId)");
                strSql.Append(" values (");
                strSql.Append("@FEntityNo,@FYear,@FTaxClassAllowanceNo,@FAdjustAmount,@FAdjustDate,@RKRQ,@FNote,@FAdjustDeptNo,@FAdjustEmpNo,@FAdjustIP,@FStatus,@FTaxAuditId)");
                SqlParameter[] parameters2 = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FAdjustAmount", SqlDbType.Decimal,13),
					new SqlParameter("@FAdjustDate", SqlDbType.DateTime),
					new SqlParameter("@RKRQ", SqlDbType.DateTime),
					new SqlParameter("@FNote", SqlDbType.NVarChar,255),
					new SqlParameter("@FAdjustDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FAdjustEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FAdjustIP", SqlDbType.NVarChar,15),
					new SqlParameter("@FStatus", SqlDbType.NVarChar,2),
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50)};
                parameters2[0].Value = modelTA.FEntityNo;
                parameters2[1].Value = modelTA.FYear;
                parameters2[2].Value = modelTA.FTaxClassAllowanceNo;
                parameters2[3].Value = modelTA.FAdjustAmount;
                parameters2[4].Value = modelTA.FAdjustDate;
                parameters2[5].Value = modelTA.RKRQ;
                parameters2[6].Value = modelTA.FNote;
                parameters2[7].Value = modelTA.FAdjustDeptNo;
                parameters2[8].Value = modelTA.FAdjustEmpNo;
                parameters2[9].Value = modelTA.FAdjustIP;
                parameters2[10].Value = modelTA.FStatus;
                parameters2[11].Value = model.FTaxAuditId;

                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters2;
                cmdList.Add(cmds);
            }

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from fund.t_TaxAudit_SB_ZSXX ");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId ");
            SqlParameter[] parameters5 = {
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50)			};
            parameters5[0].Value = model.FTaxAuditId;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters5;
            cmdList.Add(cmds);

            foreach (Model.TaxAudit_SB_ZSXX modelABZ in taxAudit_SB_ZSXXList)
            {
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("insert into fund.t_TaxAudit_SB_ZSXX(");
                strSql.Append("FTaxAuditId,FDataSource,ZSXH,FYear,FTaxClassAllowanceNo,ZSXM_DM,SE,RKRQ,SSSQ_Q,SSSQ_Z,YSKM_DM,YSFPBL_DM,YSFPBL_ZY,YSFPBL_SS,YSFPBL_DS,YSFPBL_XQ,YSFPBL_XZ,YSFPBL_XC)");
                strSql.Append(" values (");
                strSql.Append("@FTaxAuditId,@FDataSource,@ZSXH,@FYear,@FTaxClassAllowanceNo,@ZSXM_DM,@SE,@RKRQ,@SSSQ_Q,@SSSQ_Z,@YSKM_DM,@YSFPBL_DM,@YSFPBL_ZY,@YSFPBL_SS,@YSFPBL_DS,@YSFPBL_XQ,@YSFPBL_XZ,@YSFPBL_XC)");
                strSql.Append(";select @@IDENTITY");
                SqlParameter[] parameters3 = {
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50),
					new SqlParameter("@FDataSource", SqlDbType.NVarChar,2),
					new SqlParameter("@ZSXH", SqlDbType.Decimal,13),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20),
					new SqlParameter("@ZSXM_DM", SqlDbType.NVarChar,2),
					new SqlParameter("@SE", SqlDbType.Decimal,13),
					new SqlParameter("@RKRQ", SqlDbType.DateTime),
					new SqlParameter("@SSSQ_Q", SqlDbType.DateTime),
					new SqlParameter("@SSSQ_Z", SqlDbType.DateTime),
					new SqlParameter("@YSKM_DM", SqlDbType.NVarChar,15),
					new SqlParameter("@YSFPBL_DM", SqlDbType.NVarChar,10),
					new SqlParameter("@YSFPBL_ZY", SqlDbType.Decimal,5),
					new SqlParameter("@YSFPBL_SS", SqlDbType.Decimal,5),
					new SqlParameter("@YSFPBL_DS", SqlDbType.Decimal,5),
					new SqlParameter("@YSFPBL_XQ", SqlDbType.Decimal,5),
					new SqlParameter("@YSFPBL_XZ", SqlDbType.Decimal,5),
					new SqlParameter("@YSFPBL_XC", SqlDbType.Decimal,5)};
                parameters3[0].Value = model.FTaxAuditId;
                parameters3[1].Value = modelABZ.FDataSource;
                parameters3[2].Value = modelABZ.ZSXH;
                parameters3[3].Value = modelABZ.FYear;
                parameters3[4].Value = modelABZ.FTaxClassAllowanceNo;
                parameters3[5].Value = modelABZ.ZSXM_DM;
                parameters3[6].Value = modelABZ.SE;
                parameters3[7].Value = modelABZ.RKRQ;
                parameters3[8].Value = modelABZ.SSSQ_Q;
                parameters3[9].Value = modelABZ.SSSQ_Z;
                parameters3[10].Value = modelABZ.YSKM_DM;
                parameters3[11].Value = modelABZ.YSFPBL_DM;
                parameters3[12].Value = modelABZ.YSFPBL_ZY;
                parameters3[13].Value = modelABZ.YSFPBL_SS;
                parameters3[14].Value = modelABZ.YSFPBL_DS;
                parameters3[15].Value = modelABZ.YSFPBL_XQ;
                parameters3[16].Value = modelABZ.YSFPBL_XZ;
                parameters3[17].Value = modelABZ.YSFPBL_XC;

                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters3;
                cmdList.Add(cmds);
            }

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }

        }

        public void Delete(string FTaxAuditId)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();
            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from fund.t_TaxAuditAdjust ");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId ");
            SqlParameter[] parameters4 = {
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50)			};
            parameters4[0].Value = FTaxAuditId;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters4;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from fund.t_TaxAudit_SB_ZSXX ");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId ");
            SqlParameter[] parameters5 = {
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50)			};
            parameters5[0].Value = FTaxAuditId;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters5;
            cmdList.Add(cmds);

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from fund.t_TaxAuditForm ");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId ");
            SqlParameter[] parameters6 = {
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50)			};
            parameters6[0].Value = FTaxAuditId;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters6;
            cmdList.Add(cmds);

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.NSRDZDAH desc");
            }
            strSql.Append(")AS Row, T.*  from fund.t_TaxAuditForm T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_TaxAuditForm";
            parameters[1].Value = "NSRDZDAH";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

